﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;
using System.Text;
using System.Reflection;
using System.Data;
public partial class Vote : BasePage
{
    protected int id = 0;
    protected Vote_Model Md = new Vote_Model();
    protected int SumVote = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"]);
        }
        Md = Vote_Bll.CreateNew.GetModel(id);
        if (Md.Id <= 0)
        {
            Response.Write("参数错误");
            Response.End();
        }
        SumVote = Md.SumNum1 + Md.SumNum2 + Md.SumNum3 + Md.SumNum4 + Md.SumNum5 + Md.SumNum6 + Md.SumNum7 + Md.SumNum8;
    }

    protected string VoteForeach()
    {
        StringBuilder stb = new StringBuilder();
        DataTable dt = Vote_Bll.CreateNew.GetDataTable(" and  ID=" + id);
        if (dt != null)
        {
            if (dt.Rows.Count >= 0)
            {
                for (int i = 1; i <= 8; i++)
                {
                    int ImgWidth = 400;
                    int ImgWidthTwo = 0;
                    int CurrNum = 0;//当前票数
                    string CurrSelect = "";



                    if (dt.Columns.Contains("SumNum" + i))
                    {
                        CurrNum = StringHelper.isNumber_int(dt.Rows[0]["SumNum" + i]);
                    }
                    if (dt.Columns.Contains("Select" + i))
                    {
                        CurrSelect = dt.Rows[0]["Select" + i].ToString();
                    }
                    CurrSelect += "";
                    if (CurrSelect == "")
                    {
                        break;
                    }
                    string Num = Math.Round(((double)CurrNum / (double)SumVote) * 100, 2) + "%";

                    stb.AppendLine("<table width=\"700\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\" bordercolorlight=\"#000000\" bordercolordark=\"#CCCCCC\">");
                    stb.AppendLine("<tr>");
                    stb.AppendLine("<td align=\"right\">");
                    stb.AppendLine("<div align=\"left\">");
                    stb.AppendLine("<font color=\"#cc0000\"></font>");
                    stb.AppendLine("<table width=\"539\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"Images/BG2.GIF\">");
                    stb.AppendLine("<tr>");
                    stb.AppendLine(" <td height=\"23\">");
                    stb.AppendLine("    <font color=\"#cc0000\">&nbsp;</font>&nbsp;选项" + i + "：<strong>" + CurrSelect + "</strong>");
                    stb.AppendLine("</td>");
                    stb.AppendLine(" </tr>");
                    stb.AppendLine(" </table>");
                    stb.AppendLine(" </div>");
                    stb.AppendLine(" </td>");
                    stb.AppendLine(" </tr>");
                    stb.AppendLine("<tr>");
                    stb.AppendLine("   <td align=\"left\">");
                    stb.AppendLine("    <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"30\">");
                    stb.AppendLine("     <tr>");
                    stb.AppendLine(" <td height=\"11\" valign=\"top\">");
                    stb.AppendLine("    &nbsp;&nbsp; 得票率：<img src=\"Images/left.gif\" width=\"4\" height=\"21\" border=\"0\" align=\"top\"><img src='Images/greenbar.gif' width='" + ((360 * ((double)CurrNum / (double)SumVote))) + "' height='21' align='absmiddle'>");
                    stb.AppendLine("</td>");
                    stb.AppendLine("<td valign=\"top\">");
                    stb.AppendLine("<img src=\"Images/mid.gif\" width=\"6\" height=\"21\" align=\"top\"><img src='Images/whitebar.gif' width='" + (360 - (360 * ((double)CurrNum / (double)SumVote))) + "' height='21' align='absmiddle'><img src=\"Images/right.gif\" width=\"6\" height=\"21\" border=\"0\" align=\"top\">");
                    stb.AppendLine(" </td>");
                    stb.AppendLine("</tr>");
                    stb.AppendLine("<tr>");
                    stb.AppendLine("<td align=\"left\">");
                    stb.AppendLine(" </td>");
                    stb.AppendLine(" <td height=\"19\">");
                    stb.AppendLine("    占：" + Num + " [得：<font color=\"#ff0000\">" + CurrNum + "</font>票]");
                    stb.AppendLine("</td>");
                    stb.AppendLine("</tr>");
                    stb.AppendLine("</table>");
                    stb.AppendLine(" </td>");
                    stb.AppendLine("</tr>");
                    stb.AppendLine(" </table>");

                }
            }
        }
        return stb.ToString();

    }

    protected string VoteList()
    {
        string Str = "";
        DataTable dt = Vote_Bll.CreateNew.GetDataTable(" and id<>" + id);
        Str += "<ul>";
        foreach (DataRow dr in dt.Rows)
        {

            Str += "<li style=\"padding-left:60px;\"><a href='VoteShow_" + dr["id"].ToString() + ".aspx'>" + dr["title"].ToString() + "</a></li>";


        }
        Str += "</ul>";
        return Str.ToString();
    }
}
